package com.qf.controller;

import com.qf.entity.Result;
import com.qf.entity.User;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController //等价于@Controller+@ResponseBody
@RequestMapping("/user")
public class UserController4 {

    @GetMapping("/{id}") //等价于@RequestMapping(method = RequestMethod.GET)
    public Result get(@PathVariable Integer id){
        System.out.println("查询:" + id);
        User user = new User();
        user.setName("lsis");
        user.setPwd("123");
        user.setBirthday(new Date());

        return Result.success(user);
    }

    @PostMapping //等价于@RequestMapping(method = RequestMethod.POST)
    public Result add(@RequestBody User user){
        System.out.println("新增:" + user);

        return Result.success(null);
    }

    @PutMapping  //等价于@RequestMapping(method = RequestMethod.PUT)
    public Result update(@RequestBody User user){
        System.out.println("更新:" + user);

        return Result.success(null);
    }

    @DeleteMapping("/{id}")   //等价于@RequestMapping(method = RequestMethod.DELETE)
    public Result delete(@PathVariable Integer id){
        System.out.println("删除:" + id);

        return Result.success(null);
    }
}
